const mongoose = require("mongoose");

const url = `mongodb://${process.env.dbUser}:${process.env.dbPassword}@127.0.0.1:27017/moment`;
console.log(url, "url");
// 设置连接信息
// const url = "mongodb://admin:momentuser123456@127.0.0.1:27017/moment";
mongoose.connect(url, {
  useNewUrlParser: true,
  useUnifiedTopology: true,
});
// 开始连接数据库
const db = mongoose.connection;

db.on("connected", () => {
  console.log("连接成功");
});

db.on("error", (error) => {
  console.log("连接错误", error);
});

db.on("disconnected", () => {
  console.log("连接断开");
});

module.exports = mongoose;
